import axios from "axios";
import NProgress from "nprogress";
import { BASE_URL, TIME_OUT } from "./config";
const instance = axios.create({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  headers: {
    isShowProgress: true,
  },
});

instance.interceptors.request.use(
  (config) => {
    if (config.headers.isShowProgress) {
      NProgress.start();
      delete config.headers.isShowProgress;
    }
    return config;
  },
  (error) => {
    NProgress.start();
    return Promise.reject(error);
  }
);

instance.interceptors.response.use(
  (response) => {
    NProgress.done();
    return response;
  },
  (error) => {
    NProgress.done();
    return Promise.reject(error);
  }
);
export default instance;
